#include <stdio.h>
#include <arpa/inet.h>
#include <sys/types.h>

int main(void){
  unsigned short localNum=0x1f; // 保存本地主机字节序
  unsigned short networkNum; // 保存网络字节序
  networkNum = htons(localNum);
  printf("主机字节序:0x%X,转为网络子节序:0x%X\n",localNum,networkNum);
  unsigned short localNum1 = ntohs(networkNum);
  printf("网络子节序:0x%X,转为主机字节序:0x%X\n",networkNum,localNum1);
  return 0;
}